package com.hp.attendance.serlvet.attendanceManager;

import com.hp.attendance.entity.Overtime;
import com.hp.attendance.service.OvertimeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;


@WebServlet("/AddOvertime")
public class AddOvertimeServlet extends HttpServlet {
    private OvertimeService overtimeService=new OvertimeService();


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String employeeNumber = req.getParameter("employeeNumber");
        String departmentNumber = req.getParameter("departmentNumber");
        String date = req.getParameter("date");
        Overtime o = new Overtime();
        o.setEmployee_number(Integer.valueOf(employeeNumber));
        o.setDepartment_number(Integer.valueOf(departmentNumber));
        o.setDay(date);
        try {
            overtimeService.addOvertime(o);
            req.getRequestDispatcher("/overtimeMange").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
           doGet(req,resp);
    }
}
